<?php
declare (strict_types=1);

namespace app\command;

use app\api\service\CommonService;
use app\common\model\GroupModel;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;

class ToDayMessage extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('today_message')
            ->setDescription('每日新闻推送');
    }

    protected function execute(Input $input, Output $output)
    {
        $comm = new CommonService();
        $data = json_decode(file_get_contents('http://api.tianapi.com/bulletin/index?key=' . env('tx_key')), true);
        $str = "每日简报来咯 ~ \r\r";
        foreach ($data['newslist'] as $k => $v) {
            $str = $str . ($k + 1) .' 、 '. $v['title'] . "\r";
        }
        $group = (new GroupModel())->getGroupByWhere(['robot_wxid' => 'wxid_xmyit5wjvewv22']);
        foreach ($group as $v){
            $comm->send_text_msg($v['robot_wxid'], $v['wxid'], $str);
        }

    }
}
